package com.atguigu.gmall.mapper;

import com.atguigu.gmall.beans.TradeProvinceOrderAmount;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author Felix
 * @date 2024/4/29
 * 交易域统计mapper接口
 */
public interface TradeStatsMapper {
    //获取某天总交易额的方法
    @Select("select sum(order_amount)\n" +
            "from dws_trade_province_order_window\n" +
            "partition par#{date}")
    BigDecimal selectGMV(Integer date);

    //获取某天各个省份交易额
    @Select("select province_name,sum(order_amount) order_amount from dws_trade_province_order_window " +
            " PARTITION par#{date} GROUP BY province_name")
    List<TradeProvinceOrderAmount> selectProvinceAmount(Integer date);
    
    
}


//传统的API连接数据库。在SSM框架中，加注解，在注解中写SQL就行，底层是代理模式
/*
class MyC implements TradeStatsMapper {

    @Override
    public BigDecimal selectGMV(Integer date) {
        BigDecimal gmv = null;
        
        //注册驱动
        try {
            //获取连接
            Class.forName("");
            Connection conn = DriverManager.getConnection("");

            //获取数据库操作对象
            String sql = "select sum(order_amount)\n" +
                    "from dws_trade_province_order_window\n" +
                    "partition par20240430";
            PreparedStatement ps = conn.prepareStatement(sql);

            //执行SQL
            ResultSet rs = ps.executeQuery();

            //处理结果集
            rs.next();
            gmv = rs.getBigDecimal(1);


        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            //释放资源
            
        }
        
        return gmv;
    }
*/
